package com.vf.admin.client.dao;

import com.vf.admin.common.db.BaseDao;
import com.vf.admin.miaodong.entity.AppInvitationRecord;
import com.vf.admin.miaodong.entity.AppIpAuth;
import com.vf.admin.utils.StringEx;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>Title : </p>
 * <p>Description : </p>
 * <p>DevelopTools : IDEA</p>
 * <p>DevelopSystem : Windows11</p>
 *
 * @Author : zxw
 * @Date 2023/11/6 16:01
 */
@Repository
public class AppIpAuthDao extends BaseDao<AppIpAuth> {

    /**
     * 添加/修改
     */
    public void save(AppIpAuth haoYou) {
        if (haoYou.getId() != null && haoYou.getId() > 0) {
            this.update(haoYou);
        } else {
            haoYou.setId(this.add(haoYou));
        }
    }

    /**
     * 根据account查询
     */
    public AppIpAuth getAccount(String account){

        if (StringEx.isNullOrLing(account)) {
            return null;
        }
        List<Object> paramList = new ArrayList<Object>();
        StringBuilder sbStr = new StringBuilder("select * from app_ip_auth where 1=1");
        sbStr.append(" and account = ? ");
        paramList.add(account);
        String sql = sbStr.toString();
        return this.queryObj(sql, paramList, AppIpAuth.class);

    }

    public AppIpAuth getIp(String ip){

        if (StringEx.isNullOrLing(ip)) {
            return null;
        }
        List<Object> paramList = new ArrayList<Object>();
        StringBuilder sbStr = new StringBuilder("select * from app_ip_auth where 1=1");
        sbStr.append(" and ip = ? ");
        paramList.add(ip);
        String sql = sbStr.toString();
        return this.queryObj(sql, paramList, AppIpAuth.class);

    }


    public List<AppIpAuth> getAccountList(String account) {

        if (StringEx.isNullOrLing(account)) {
            return null;
        }
        List<Object> paramList = new ArrayList<Object>();
        StringBuilder sbStr = new StringBuilder("select * from app_ip_auth where 1=1");
        sbStr.append(" and account = ? ");
        paramList.add(account);
        String sql = sbStr.toString();
        return this.queryList(sql, paramList, AppIpAuth.class);
    }

    public List<AppIpAuth> getIpList(String ipAddress) {

        if (StringEx.isNullOrLing(ipAddress)) {
            return null;
        }
        List<Object> paramList = new ArrayList<Object>();
        StringBuilder sbStr = new StringBuilder("select * from app_ip_auth where 1=1");
        sbStr.append(" and ip = ? ");
        paramList.add(ipAddress);
        String sql = sbStr.toString();
        return this.queryList(sql, paramList, AppIpAuth.class);
    }
}
